<script>
	import uniIdPageInit from '@/uni_modules/uni-id-pages/init.js'
	import Vue from 'vue'
	export default {
		globalData: {
			//Imgbase:'http://tong.localhost.test/front',
			//Imgbase:"https://api.oqzhs.cn/front",
			Imgbase: "https://oqyf-1305090490.cos.ap-shanghai.myqcloud.com/front",
			//Imgbase:"https://api.tonggo.top/front",
			couldFresh: true,
			page: '',
			explainMes: {
				1: '',
				2: '',
				3: '',
				4: '',
				5: '',
				6: '',
				7: '',
				8: '',
				9: ''
			},
		},
		onLaunch: async function() {
			uni.hideTabBar()

			// const res = await uniCloud.initSecureNetworkByWeixin({
			// 	callLoginByWeixin: true
			// })
			await uniIdPageInit()



			// #ifdef MP-WEIXIN
			// 调用自有服务、云函数进行微信登录或以其他方式获取openid user_desc userUnique
			let _this = this;
			var openid = ''
			await uni.request({
				url: _this.$globals.apibase + '/api/Userways/userFront',
				data: {
					token: uni.getStorageSync('token'),
				},
				success: (res) => {
					openid = res.data.data.user_desc.userUnique.open_id

					uniCloud.initSecureNetworkByWeixin({
						openid: openid
					})
				}

			});

			uni.checkSession({
				success: (res) => {
					console.log(11111, res)

				},
				fail(res) {
					console.log(22222, res)
					uni.showToast({
						icon: 'none',
						title: '登录过期，请重新登录',
					});
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}, 1000)
				}
			})




			// #endif

			// uni.checkSession()


			uni.onTabBarMidButtonTap(() => {
				uni.navigateTo({
					url: '/pages/goodspoor/index'
				});
			})

			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					uni.setStorageSync('backpack', 0);
					// #endif		

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})

			/*if (wx.canIUse('getUpdateManager')) {
				const updateManager = wx.getUpdateManager()
				updateManager.onCheckForUpdate(function (res) {
				// 请求完新版本信息的回调
				if (res.hasUpdate) {
					console.log('res.hasUpdate====')
					updateManager.onUpdateReady(function () {
					wx.showModal({
						title: '更新提示',
						content: '新版本已经准备好，是否重启应用？',
						success: function (res) {
						console.log('success====', res)
						if (res.confirm) {
							updateManager.applyUpdate()
						}
						}
					})
					
					})
					updateManager.onUpdateFailed(function () {
					// 新的版本下载失败
					wx.showModal({
						title: '已经有新版本了哟~',
						content: '新版本已经上线啦~，请您删除当前小程序，重新搜索(你的小程序名字)小程序打开哟~',
						showCancel:false
					})
					})
				}
				})
			},*/
			// #ifdef APP-PLUS 
			let _this = this;
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				uni.request({
					url: _this.$globals.apibase + '/api/Applogin/appversion',
					data: {
						versioncode: widgetInfo.versionCode,
						name: widgetInfo.name
					},
					success: (result) => {
						var data = result.data;
						if (result.data.data.update == 1) {
							let wgtUrl = result.data.data.desc.wgeturl;
							uni.showModal({
								title: "发现新版本",
								content: "确认下载更新",
								success: (res) => {
									if (res.confirm) { //当用户确定更新，执行更新
										_this.doUpData(wgtUrl);
									} else if (res.cancel) {
										plus.runtime.quit();
									}
								}
							})
						} else {
							//加载系统配置
							for (var i = 1; i <= 9; i++) {
								const index = i;
								uni.request({
									url: _this.$globals.apibase + '/api/Index/explain',
									data: {
										id: i
									},
									method: 'POST',
									header: {
										'content-type': 'application/json'
									},
									success: (res) => {
										getApp().globalData.explainMes[index] = res
											.data.data.desc;
									}
								});
							}
						}
					}
				});
			});
			// #endif


			// setTimeout(function() {
			// 	uni.switchTab({
			// 		url: 'pages/index/kpindex',
			// 		complete(res) {
			// 			console.log(res)
			// 		}
			// 	});
			// }, 2000)
		},
		methods: {

			doUpData(wgtUrl) {
				uni.showLoading({
					title: '更新中……'
				})
				uni.downloadFile({
					url: wgtUrl,
					success: downloadResult => {
						if (downloadResult.statusCode === 200) {
							uni.showModal({
								title: '',
								content: '更新成功，确定现在重启吗？',
								confirmText: '重启',
								confirmColor: '#EE8F57',
								success: function(res) {
									if (res.confirm) {
										plus.runtime.install( //安装
											downloadResult.tempFilePath, {
												force: true
											},
											function() {
												plus.runtime.restart();
											},
											function(e) {
												plus.runtime.quit();
											}
										);
									}
								}
							});
						}
					},
					complete: () => {
						uni.hideLoading();
					}
				});
			},
			sss() {
				uni.setTabBarStyle({
					backgroundImage: '/static/images/bgs.png',
					backgroundRepeat: 'repeat'
				})
			},
		},
		onShow: function() {},
		onHide: function() {},


	}
</script>

<style lang="scss">
	// @import "@/uni_modules/uview-ui/index.scss";
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "colorui/common.scss";

	page {
		// background-color: #F0E3CE;
	}



	.tabbars {
		position: fixed;
		bottom: 0;
		left: 0;
		padding: 0 15rpx;
		z-index: 99;

		.bgcs {
			position: absolute;
			bottom: 0%;
			left: 0;
			width: 100%;
			height: 45rpx;
			background-color: #EE9A52;
		}

		.bgcs_top {
			position: absolute;
			bottom: 45rpx;
			left: 0;
			background: linear-gradient(to bottom, rgba(238, 155, 85, .1), rgba(238, 155, 85, 1));
			width: 100%;
			height: 30rpx;
		}
	}


	.nav-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0px 40upx 0px;
		justify-content: space-between;
	}

	.nav-li {
		padding: 30upx;
		border-radius: 12upx;
		width: 45%;
		margin: 0 2.5% 40upx;
		background-image: url(https://cdn.nlark.com/yuque/0/2019/png/280374/1552996358352-assets/web-upload/cc3b1807-c684-4b83-8f80-80e5b8a6b975.png);
		background-size: cover;
		background-position: center;
		position: relative;
		z-index: 1;
	}


	.nav-li::after {
		content: "";
		position: absolute;
		z-index: -1;
		background-color: inherit;
		width: 100%;
		height: 100%;
		left: 0;
		bottom: -10%;
		border-radius: 10upx;
		opacity: 0.2;
		transform: scale(0.9, 0.9);
	}

	.nav-li.cur {
		color: #fff;
		background: rgb(94, 185, 94);
		box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
	}

	.nav-title {
		font-size: 32upx;
		font-weight: 300;
	}

	.nav-title::first-letter {
		font-size: 40upx;
		margin-right: 4upx;
	}

	.nav-name {
		font-size: 28upx;
		text-transform: Capitalize;
		margin-top: 20upx;
		position: relative;
	}

	.nav-name::before {
		content: "";
		position: absolute;
		display: block;
		width: 40upx;
		height: 6upx;
		background: #fff;
		bottom: 0;
		right: 0;
		opacity: 0.5;
	}

	.nav-name::after {
		content: "";
		position: absolute;
		display: block;
		width: 100upx;
		height: 1px;
		background: #fff;
		bottom: 0;
		right: 40upx;
		opacity: 0.3;
	}

	.nav-name::first-letter {
		font-weight: bold;
		font-size: 36upx;
		margin-right: 1px;
	}

	.nav-li text {
		position: absolute;
		right: 30upx;
		top: 30upx;
		font-size: 52upx;
		width: 60upx;
		height: 60upx;
		text-align: center;
		line-height: 60upx;
	}

	.text-light {
		font-weight: 300;
	}

	@keyframes show {
		0% {
			transform: translateY(-50px);
		}

		60% {
			transform: translateY(40upx);
		}

		100% {
			transform: translateY(0px);
		}
	}

	@-webkit-keyframes show {
		0% {
			transform: translateY(-50px);
		}

		60% {
			transform: translateY(40upx);
		}

		100% {
			transform: translateY(0px);
		}
	}
</style>